/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package braipetro.interfaces.regras;

import java.util.logging.Logger;
import javafish.clients.opc.JEasyOpc;
import javafish.clients.opc.JOpc;
import javafish.clients.opc.component.OpcGroup;
import javafish.clients.opc.component.OpcItem;
import javafish.clients.opc.exception.ComponentNotFoundException;
import javafish.clients.opc.exception.ConnectivityException;
import javafish.clients.opc.exception.SynchReadException;
import javafish.clients.opc.exception.UnableAddGroupException;
import javafish.clients.opc.exception.UnableAddItemException;
import javax.swing.JOptionPane;

/**
 *
 * @author manasses
 */
public class Foo {
    
    public Foo() {}
    
    private static int count = 0;
    
    public static void mensagem() {
        JOptionPane.showMessageDialog(null, "Chamou metodo mensagem sem parametro");
    }
    
    public static void mensagem(String str) {
        JOptionPane.showMessageDialog(null, str);
    }
    
    public static void mensagem(String str, Integer num){
        JOptionPane.showMessageDialog(null, str + ": " + num.toString());
    }
    
    public static Integer soma(Integer num1, Integer num2){
        return num1 + num2;
    }
    
    public static Integer getX(){        
        count += 10;
        
        System.out.println("contador = " + count);
        
        if (count == 100) count = 0;
        
        return count;
    }
    
    public static void alerta(){
        System.out.println("Regra Disparada");
    }
    
    public static void EnviarEmail() {
        //email.CommonsMail.enviaEmailSimples("manasseslima@gmail.com");
        //System.out.println("Email enviado");
    }
    
    public static Double getTag() {
          try {  
              JOpc.coInitialize();
            
              JEasyOpc opc = new JEasyOpc("localhost", "ElipseSCADA.OPCSvr.1", "JOPC1");
            
              OpcItem item = new OpcItem("tag001", true, "");
              OpcGroup group = new OpcGroup("Grupo01", true, 500, 0.0f);
            
            group.addItem(item);
            opc.addGroup(group);
            
            opc.connect();
            opc.start();
            opc.registerGroups();
        
            
            
            int circles = 7;
            int acircles = 0;
            
            while (acircles++ < circles) {
                
                
                OpcItem resp = opc.synchReadItem(group, item);         
                System.out.println(resp);
            }
            
            JOpc.coUninitialize();
           
        } catch (ConnectivityException ex) {
              
        } catch (UnableAddGroupException ex) {
            
        } catch (ComponentNotFoundException ex) {
            
        } catch (SynchReadException ex) {
            
        } catch (UnableAddItemException ex) {
            
        }
        
        return 0.0;
    }

}
